<template>
    <el-card class="m_t_b_10px xd-LearningHome-PoliticalNews-NewsDetail" shadow="hover">
        <div slot="header" class="clearfix">
            <p class="new-title">
                <b v-text="decode(detail.v_seach_v_notice_title)"></b>
            </p>
            <div class="text_color_999999 text_size_7 desc">
                <span>作者：{{detail.author}}</span>
                <span>图片来源：{{detail.imgsource}}</span>
                <span>发布人：{{detail.publisher}}</span>
                <span>发布日期：{{detail.dtm_publish_date}}</span>
            </div>
        </div>
        <pre v-html="decode(detail.v_notice_content)"></pre>
        <div v-for="(p,index) in detail.files" v-bind:key="index" style="line-height: 25px;" class="text_size_7">
            <a v-show="p.fileName" title="点击下载" target="_blank" @click="registerDownnum(p)" :href="baseUrl+'/notice/downtaskAffix?file_id='+p.id" style="text-decoration: none;color:#006756;">【{{p.fileName}}】</a>
            <span class="text_color_999999 desc">下载 {{p.downnum}} 次</span>
        </div>
    </el-card>
</template>
<script>
export default {
    name: 'NewsDetail',
    data() {
        return {
            baseUrl: utils.baseURL,
            detail: {
                v_notice_title: '',
                v_notice_content: ''
            }
        };
    },
    watch: {
        $route: 'refresh'
    },
    mounted() {
        var activeMenu = this.$route.query.activeMenu || '/LearningHome/PoliticalNews';
        this.$store.commit('updateActiveMenu', activeMenu);
        var id = this.$route.query.id;
        this.getDetail(id);
        utils.goTop();
    },
    methods: {
        registerDownnum(obj) {
            obj.downnum = parseInt(obj.downnum) + 1;
            this.$forceUpdate();
        },
        getDetail(id) {
            utils.post(utils.api.politicalInfo.newsDetail, { i_id: id }, res => {
                if (res.success) {
                    this.detail = res.data;
                    if (this.detail.dtm_publish_date) {
                        this.detail.dtm_publish_date = this.detail.dtm_publish_date.substr(0, 10);
                    }
                    this.detail.files = [];
                    if (this.detail.v_affix_id) {
                        var idArray = this.detail.v_affix_id.split('|');
                        var nameArray = this.detail.v_affix_name.split('|');
                        var downnumArray = this.detail.v_downnum.split('|');
                        for (let i = 0; i < idArray.length; i++) {
                            var id = idArray[i];
                            var name = nameArray[i];
                            var downnum = downnumArray[i];
                            this.detail.files.push({ id: id, fileName: name, downnum: downnum });
                        }
                    }
                }
            });
        },
        decode(value) {
            var result = '';
            try {
                result = decodeURI(value);
            } catch (ex) {
                console.warn(ex);
                result = value;
            }
            return result == 'undefined' ? '' : result;
        },
        refresh(item) {
            this.getDetail(item.query.id);
        }
    }
};
</script>
<style lang="less">
.xd-LearningHome-PoliticalNews-NewsDetail {
    .new-title {
        font-size: 22px;
    }
    .clearfix {
        text-align: center;
        .desc {
            span {
                margin-right: 25px;
            }
        }
    }
}
</style>